//
//  RCImpressiveListDataModel.m
//  RocketProject
//
//  Created by chen jiedan on 13-9-28.
//  Copyright (c) 2013年 Rocket. All rights reserved.
//

#import "RCImpressiveListDataModel.h"
#import "KFObjectExtension.h"


@implementation RCImpressiveItemDataModel

@synthesize commentID = _commentID;
@synthesize userName    = _userName;
@synthesize content = _content;
@synthesize title =_title;
//@synthesize phone   = _phone;
@synthesize datetime= _datetime;


- (void) dealloc
{
    KF_RELEASE_SAFELY(_commentID);
    KF_RELEASE_SAFELY(_userName);
    KF_RELEASE_SAFELY(_title);
    KF_RELEASE_SAFELY(_content);
    //    KF_RELEASE_SAFELY(_phone);
    //    KF_RELEASE_SAFELY(_personCount);
    KF_RELEASE_SAFELY(_datetime);
    [super dealloc];
}
@end


@implementation RCImpressiveListDataModel

// 将JSON数据解析为数据模型
+(id) parseDataFromJSON:(NSDictionary*)data
{
    // 输入参数判断
    if ( nil == data )
        return nil;
    NSMutableArray *listItems = [[NSMutableArray alloc] init];
    
    RCImpressiveListDataModel *retObject = [[[RCImpressiveListDataModel alloc] init] autorelease];
    NSDictionary *dataDic = [data dictionaryValueForKey:@"data" defaultValue:nil];
    retObject.pn     = [dataDic intValueForKey:@"pn" defaultValue:0];
    retObject.rn     = [dataDic intValueForKey:@"rn" defaultValue:0];
    retObject.total  = [dataDic intValueForKey:@"total" defaultValue:0];
    
    NSArray *dataItems = [dataDic arrayValueForKey:@"list" defaultValue:nil];
    if (nil == dataItems) {
        dataItems = [dataDic arrayValueForKey:@"items" defaultValue:nil];
    }
    for (NSDictionary *dic in dataItems) {
        RCImpressiveItemDataModel *item = [[RCImpressiveItemDataModel alloc] init];
        item.content = [dic stringValueForKey:@"content" defaultValue:@"" operation:NSStringOperationTypeNone];
        item.userName = [dic stringValueForKey:@"username" defaultValue:@"" operation:NSStringOperationTypeNone];
        item.title = [dic stringValueForKey:@"title" defaultValue:@"" operation:NSStringOperationTypeNone];
        item.commentID = [dic stringValueForKey:@"id" defaultValue:@"" operation:NSStringOperationTypeNone];
        //        item.type = [dic stringValueForKey:@"type" defaultValue:@"" operation:NSStringOperationTypeNone];
        //        item.phone = [dic stringValueForKey:@"phone" defaultValue:@"" operation:NSStringOperationTypeNone];
        item.datetime = [dic stringValueForKey:@"datetime" defaultValue:@"" operation:NSStringOperationTypeNone];
        [listItems addObject:item];
        [item release];
    }
    retObject.listItems = listItems;
    [listItems release];
    return retObject;
}

@end
